package org.dwell.urlfilter.demo.test;

import org.dwell.urlfilter.demo.domain.CoreModule;
import org.dwell.urlfilter.demo.domain.CorePrivilege;
import org.dwell.urlfilter.demo.domain.CoreRole;
import org.dwell.urlfilter.demo.domain.CoreUserRole;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jange on 2016/4/6.
 */
public class CoreRoleModuleDB {
    private static List<CorePrivilege> corePrivileges = new ArrayList<CorePrivilege>();

    //String privilegeId, String who, String whoValue, String what, String whatValue, Integer needCheck
    static {
        //坚果的权限
        corePrivileges.add(new CorePrivilege("priv000000001", "module", "md00001", "role", "role000000001", 1));
        corePrivileges.add(new CorePrivilege("priv000000002", "module", "md00002", "role", "role000000001", 1));
        corePrivileges.add(new CorePrivilege("priv000000003", "module", "md00003", "role", "role000000001", 1));
        corePrivileges.add(new CorePrivilege("priv000000004", "module", "md00004", "role", "role000000001", 1));
        corePrivileges.add(new CorePrivilege("priv000000005", "module", "md00005", "role", "role000000001", 1));

        //芒果的权限
        corePrivileges.add(new CorePrivilege("priv000000006", "module", "md00001", "role", "role000000002", 1));
        corePrivileges.add(new CorePrivilege("priv000000007", "module", "md00002", "role", "role000000002", 1));
    }

    public static List<CoreModule> listByRoleId(String roleId) {
        List<CoreModule> result = new ArrayList<CoreModule>();
        CoreModule coreModule = null;
        for (CorePrivilege corePrivilege : corePrivileges) {
//            System.out.println(corePrivilege.getWhat() + " - " + corePrivilege.getWhatValue());
            if(corePrivilege.getWhat().equalsIgnoreCase("role") && corePrivilege.getWhatValue().equalsIgnoreCase(roleId)) {
                coreModule = CoreModuleDB.getByModuleId(corePrivilege.getWhoValue());

                if(null != coreModule) {
                    result.add(coreModule);
                }
            }
        }

        result.addAll(CoreModuleDB.getNoNeedAuthModules());
        return result;
    }
}
